package com.example.commonexport.controller;

import com.example.commonexport.entity.ExportType;
import com.example.commonexport.model.Response;
import com.example.commonexport.service.*;
import com.example.commonexport.service.impl.CsvExportServiceImpl;
import com.example.commonexport.service.impl.ExportTaskImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;

@RestController
public class CommonExportController {

    @Autowired
    ExportTaskExecutor exportTaskExecutor;

    /**
     * 查询导出任务清单
     */
    @PostMapping("export/task/new")
    public Response queryTaskList(@RequestBody HashMap param){
        Response res = new Response();

       return res;
    }

    /**
     * 新建一个导出任务
     */
    @PostMapping("export/task/new")
    public Response createTask(@RequestBody HashMap param){
        String taskId = "TASK-" + System.currentTimeMillis() + "-output";
        // 创建导出excel的服务实例
        ExportService exportService = new CsvExportServiceImpl("D:\\temp\\");
        ExportTask task = new ExportTaskImpl(taskId, ExportType.CSV, exportService);

        exportTaskExecutor.submitExportTask(task);
        return null;
    }



}
